/**
 * file name:		SignalResult.java
 * copyright:		© 2009 Kingsoft
 * author:			TanMenglong
 * version:			?.??
 * created:			2009-08-10
 * last modified:	2009-08-10
 * description:		HERE
 */

public class  SignalResult{
	public final static int RC_ALLSUCCESS	= 0x0;
	public final static int RC_FAILED		= 0x1;
	public final static int RC_UNFINISHED	= 0x2;
	public final static int RC_NOT_FOUND		= 0x4;

	/**
	 * return code specification
	 * code is used in a mask way, namely, every bit represents a flag.
	 * build or extract flags from the code should use bit-operations.
	 * 
	 * ** caution **
	 * the 4 low bits are reserved for BrickManager and cann't be
	 * overwritten. flags in other bits will be considered unknown errors by
	 * BrickManager but still can be sent back to client.
	 * 
	 * ** flags in hex view **
	 * 0x0000 0001	execution failed
	 * 0x0000 0002	unfinished
	 * 0x0000 0004	brick not found
	 */
	public int m_returnCode;

	public boolean isAllSuccessful() {
		return m_returnCode == 0;
	}
	
	public void setAllSuccessful(boolean isAllSuccessful) {
		if (isAllSuccessful) {
			m_returnCode = 0;
		} else {
			m_returnCode = ~0;
		}
	}
	
	public boolean isSuccessful() {
		return (m_returnCode & RC_FAILED) == 0;
	}

	public void setSuccessful(boolean isSuccessful) {
		if (isSuccessful) {
			// clear failed flag
			m_returnCode &= ~RC_FAILED;
		} else {
			// set failed flag
			m_returnCode |= RC_FAILED;
		}
	}

	public boolean isFinished() {
		return (m_returnCode & RC_UNFINISHED) == 0;
	}

	public void setFinished(boolean isFinished) {
		if (isFinished) {
			// clear unfinished flag
			m_returnCode &= ~RC_UNFINISHED;
		} else {
			// set unfinished flag
			m_returnCode |= RC_UNFINISHED;
		}
	}
}

